package com.financing.platform.dao.impl;

import java.sql.SQLException;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

import org.springframework.stereotype.Repository;

import com.financing.platform.dao.IManagerOrderDao;
import com.financing.platform.dto.ManagerOrderDTO;
import com.financing.platform.dto.ManagerOrderHistoryDTO;
import com.financing.platform.util.SqlName;
import com.financing.platform.util.StringUtil;
import com.financing.platform.vo.ManagerOrderVO;
import com.financing.platform.vo.OrderVO;

@Repository("managerOrderDaoImpl")
public class ManagerOrderDaoImpl extends BaseDaoImpl implements IManagerOrderDao {

	@Override
	public int addManagerOrderUser(ManagerOrderDTO managerOrder) throws SQLException {
		return (Integer) this.sqlMapClient.insert(SqlName.addManagerOrderUser, managerOrder);
	}

	@Override
	public int addManagerOrderUserHistory(ManagerOrderHistoryDTO managerOrderHistory) throws SQLException {
		return (Integer) this.sqlMapClient.insert(SqlName.addManagerOrderUserHistory, managerOrderHistory);
	}

	@Override
	public int updateManagerOrderUser(ManagerOrderDTO managerOrder) throws SQLException {
		return (Integer) this.sqlMapClient.update(SqlName.updateManagerOrderUser, managerOrder);
	}

	@SuppressWarnings("unchecked")
	@Override
	public List<ManagerOrderVO> queryManagerOrderByOrderIds(String orderIds) throws SQLException {
		//处理 str 带有''
		orderIds=StringUtil.splitToIn(orderIds);
		return this.sqlMapClient.queryForList(SqlName.queryManagerOrderByOrderIds, orderIds);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<ManagerOrderVO> queryManagerOrderByOrderTmpIds(String orderIds) throws SQLException {
		//处理 str 带有''
				orderIds=StringUtil.splitToIn(orderIds);
		return this.sqlMapClient.queryForList(SqlName.queryManagerOrderByOrderTmpIds, orderIds);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<ManagerOrderVO> queryManagerOrderByUser(String systemUserId) throws SQLException{
		return this.sqlMapClient.queryForList(SqlName.queryManagerOrderByUser,systemUserId);
	}
	
	@SuppressWarnings("unchecked")
	@Override
	public List<HashMap<String, Object>> queryFaUserBySystemUser(Map<String,String> faids) throws SQLException{
		return this.sqlMapClient.queryForList(SqlName.queryFaUserBySystemUser, faids);
	}
	@Override
	public int countOrdersBySUid(ManagerOrderDTO managerOrder) throws SQLException {
		
		return (Integer) this.sqlMapClient.queryForObject(SqlName.countOrdersBySUid, managerOrder);
	}
 
	@SuppressWarnings("unchecked")
	@Override
	public List<OrderVO> queryOrdersBySUid(ManagerOrderDTO managerOrder) throws SQLException {
		
		return this.sqlMapClient.queryForList(SqlName.queryOrdersBySUid, managerOrder);
	}

	@Override
	public void order2Leader(Map<String, Object> toLeaderMap) throws SQLException {
		this.sqlMapClient.update(SqlName.order2Leader, toLeaderMap);
	}
}
